home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Portable Patmos / src / portable kernel / ncsasock / syslog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-12  |  1.8 KB  |  95 lines  |  [TEXT/R*ch]

  1. /*
  2.  * BSD-style socket emulation library for the Mac
  3.  * Original author: Tom Milligan
  4.  * Current author: Charlie Reiman - creiman@ncsa.uiuc.edu
  5.  *
  6.  * This source file is placed in the public domian.
  7.  * Any resemblance to NCSA Telnet, living or dead, is purely coincidental.
  8.  *
  9.  *      National Center for Supercomputing Applications
  10.  *      152 Computing Applications Building
  11.  *      605 E. Springfield Ave.
  12.  *      Champaign, IL  61820
  13.  */
  14.  
  15. /*
  16.  * syslog, openlog, closelog - hacked from Unix - use dprintf
  17.  * perror - hacked from Unix - uses dprintf
  18.  * Modified to use StdArg by Charlie Reiman.
  19.  * Wednesday, August 8, 1990 2:55:43 PM
  20.  */
  21.  
  22. #include <syslog.h>
  23. #include <StdArg.h>
  24.  
  25. extern int errno;
  26. extern int sys_nerr;
  27. extern char *sys_errlist[];
  28.  
  29. /*
  30.  * a version of dprintf was here, but it was also defined in
  31.  * dprintf.c. I've removed this one.
  32.  * Charlie Reiman
  33.  * Wednesday, August 8, 1990 2:53:49 PM
  34.  */
  35.  
  36. #define MAXLINE 1000
  37.  
  38. static int LogMask = LOG_DEBUG;
  39. static char LogTag[100] = "";
  40.  
  41. openlog(char *ident, int logstat)
  42. {
  43.     if (logstat >= LOG_ALERT && logstat <= LOG_DEBUG)
  44.         LogMask = logstat;
  45.         
  46.     if (ident)
  47.         strcpy(LogTag,ident);
  48. }
  49.  
  50. closelog()
  51. {
  52. }
  53.  
  54. syslog(int pri,char *fmt,...)
  55. {
  56.     register char *b, *f = fmt, c;
  57.     char buf[MAXLINE+50];
  58.     char oline[MAXLINE];
  59.     va_list nextArg;
  60.     
  61.     va_start(nextArg,fmt);
  62.     
  63.     if (pri > LogMask)
  64.         return;
  65.  
  66.     b = buf;
  67.     while ((c = *f++) != '\0' && b < buf + MAXLINE) 
  68.     {
  69.         if (c != '%') 
  70.         {
  71.             *b++ = c;
  72.             continue;
  73.         }
  74.         c = *f++;
  75.         if (c != 'm') 
  76.         {
  77.             *b++ = '%', *b++ = c;
  78.             continue;
  79.         }
  80.         if ((unsigned)errno > sys_nerr)
  81.             sprintf(b, "error %d", errno);
  82.         else
  83.             sprintf(b, "%s", (int)sys_errlist[errno]);
  84.         b += strlen(b);
  85.     }
  86.     if (b[-1] != '\n')
  87.         *b++ = '\n';
  88.     *b = '\0';
  89.         
  90.     vsprintf(oline, buf, nextArg);
  91.  
  92.     dprintf("%s: %s\n", LogTag,oline);
  93. }
  94.  
  95.